package ru.vasilij.selenium.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.testng.Assert;

public class FilmAddPage extends InternalPage {
	
	public FilmAddPage(PageManager pages) {
		super(pages);
	}
	
	@FindBy(name = "imdbid")
	private WebElement imdbidField;
	
	@FindBy(name = "name")
	private WebElement nameField;
  
	@FindBy(name = "year")
	private WebElement yearField;
  
	@FindBy(name = "notes")
	private WebElement notesField;
	
	@FindBy(name = "submit")
	private WebElement submitButton;
	
	public FilmAddPage setnameField(String text) {
		nameField.sendKeys(text);
		return this;
	}
	
	public FilmAddPage setyearField(String text) {
		yearField.sendKeys(text);
		return this;
	}
	
	public void clickSubmitButton() {
		submitButton.click();
	}
	
	public FilmAddPage ensurePageLoaded() {
		super.ensurePageLoaded();
		wait.until(presenceOfElementLocated(By.cssSelector("input#imdbsearch")));
		return this;
	}

	public boolean isErrorFiled() {
		return driver.findElements(By.cssSelector("form#updateform input.error")).size() > 0;
	}
	
}
